package Thread.Thread_State;
/**
 * 三种阻塞状态
 */
public class BlockedState2 {
    public static void main(String[] args) {
        Object lock=new Object();
        Thread t1=new Thread(()->{
            synchronized (lock){
                    try {
                        //TIME_WAITING 等待时间到了自动唤醒
//                       Thread.sleep(1000);
                        //线程等待
                        lock.wait();
                        System.out.println("t1被唤醒了~~~");
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
        },"t1线程~~");
        t1.start();
        Thread t2=new Thread(()->{
            synchronized (lock){
                //BLOCKED 等待获取锁对象
                System.out.println("哈哈哈哈~~~");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                //唤醒t1线程
                lock.notify();
            }
        },"t2线程~~");
        t2.start();
    }
}